

const inp = document.querySelector('.shop-search>input')
const ul = document.querySelector('.shop-search>ul')

inp.oninput = function () {
    const text = this.value.trim()

    const script = document.createElement('script')
    script.src = `https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=34305,34099,33970,34273,34278,34004,34281,34107,34111,26350,22159&wd=${ text }&req=2&csor=2&cb=fn&_=1627023610785`

    document.body.appendChild(script)
    script.remove()
}

function fn(res) {
    if (!res.g) {

        ul.classList.remove('active')
        return
    }

    let str = ''
    res.g.forEach(item => {
        str += `<li>${ item.q }</li>`
    })
    // 插入到 ul 内部
    ul.innerHTML = str

    ul.classList.add('active')
}